<html>
<head>
    <title>Submit Confirmation Letter</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <script type="text/javascript" src="<?=base_url()?>resource/js/jquery.js"></script>
    
    <link rel="stylesheet" href='<?=base_url()?>resource/css/style.css' type="text/css"/>
    
    <link rel="stylesheet" type="text/css" href="<?=base_url()?>resource/css/jquery.datetimepicker.css" />
    <script src="<?=base_url()?>resource/js/jquery.datetimepicker.js"></script>
    
    <link rel="stylesheet" type="text/css" href="<?=base_url()?>resource/css/jquery.autocompleter.css" />
    <script src="<?=base_url()?>resource/js/jquery.autocompleter.js"></script>
    <script type="text/javascript">
        function readURL(input,id) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();
                reader.onload = function (e) {
                    $('#'+id).val(input.value);
                };
                reader.readAsDataURL(input.files[0]);
            }
        }
    </script>
</head>
<body>
    <div class="submit-header">
        <h3><?=$title?></h3>
    </div>
    <div class="list-div">
        <?php echo form_open('profile/submit_confirmation_letter/'.$candidates[0]['ordersn']); ?>
        <table class="top-table">
            <tr>
                <td>Candidate List</td>
                <td width="240" class="center">
                    <input type="text" placeholder="input candidate name" name="condition" value="<?=$condition?>"/>
                </td>
                <td width="90" class="center"><input type="submit" value="Search" /></td>
            </tr>
        </table>
        <?php echo form_close(); ?>
        <table class="list-table">
            <tr>
                <th>Name</th>
                <th width="460">Confirmation Letter</th>
                <th width="100">Save</th>
            </tr>
            <?php foreach ($candidates as $key => $value) {?>
            <tr>
                <td id="tdname<?=$value['id']?>"><?=$value['name']?></td>
                <td class="relative">
                    <?php echo form_open_multipart('profile/edit_confirmationletter/'.$value['id']); ?>
                        <input type="hidden" value="<?=$value['confirmationletter']['id']?>" name="id"/>
                        <input type="hidden" value="<?=$value['ordersn']?>" name="orderid"/>
                        <input type="hidden" value="<?=$value['name']?>" name="workername"/>
                        <input type="text" value="<?=$value['confirmationletter']['path']?>" id="path<?=$value['id']?>"/>
                        <img src="<?=base_url()?>resource/img/upload.png" width="25" height="29" style="position:absolute;right:10px;top:3px;" />
                        <input type="file" id="path" class="inputfile" name="path" size="20" onchange="readURL(this,'path<?=$value['id']?>');" 
                               style="position:absolute;width:25px;height:29px;right:10px;top:3px;cursor:pointer;opacity:0;filter:alpha(opacity=0);"/>
                        <input type="submit" style="position:absolute;width:29px;height:29px;background:#ffffff url(<?=base_url()?>resource/img/save.png) no-repeat;
                               background-repeat:round;right:-60px;top:4px;cursor:pointer;border:none;" value=""/>
                    <?php echo form_close(); ?>
                </td>
                <td></td>
            </tr>
            <?php }?>
            <tr>
                <td colspan="3">
                    <input type="button" id="submit" value="Turn Profile" />
                </td>
            </tr>
        </table>
    </div>
<script>
$("#submit").click(function(){
//    var flag = true;
//    <?php foreach ($candidates as $key => $value) {
        $confirmationletter = $value['confirmationletter'];
        if($confirmationletter['id']*1 == 0){?>//
//            flag = false;
//    <?php }
    }?>//
//    if(flag){
    var storage = window.localStorage; 
    storage.setItem("profileid","index");
    var url = "<?=base_url()?>profile/turn2profile/<?=$orderid?>";
    window.opener.location.href=url; //重新定位父页面
    window.close();
//    }else{
//        alert("Please upload worker's confirmation letter.");
//    }
});
</script>
</body>
</html>